08. Give That App a Backend
Ud197 RDB REDO L3 09Q Give That App A Back End V2
The forum
database has already been created for you in the virtual machine that you downloaded. Your code will need to connect to it using psycopg2.connect("dbname=forum")
and then perform select
and insert
operations on the posts
table.
The existing get_posts
function returns all the entries from a list. So its database version should return all the entries from the posts
table.
And likewise, the existing add_post
function inserts an entry into a list.
You do not need to provide the time
column when you insert a post. The table is set up to already provide a timestamp.
The existing get_posts
function puts the posts in order using a Python reversed
function. When you implement this function using the database, can you put the posts in order using only SQL?
Task Description:
Update the forumdb.py
code to use the database.
Task Feedback:
Great!
Solution (almost):
Ud197 RDB REDO L3 09S Solution Give That App A Back End
Errata:
There is a mistake in the code in the video above. Lines 14 and 15 should be swapped, so that db.close()
is called before the get_posts
function returns.
The code appears correctly in the video at the top of the next page.